﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ChiantiPhoneListApp
{
    public class Utilities
    {
        internal static string CreateExpiresInString(TimeSpan timeTillExpiry)
        {
            string dayMsg = string.Empty;

            if (timeTillExpiry.Ticks <= 0)
            {
                return "Expired";
            }

            if (timeTillExpiry.Days == 1)
            {
                dayMsg = string.Format("{0} day,", timeTillExpiry.Days);
            }
            else if (timeTillExpiry.Days > 1)
            {
                dayMsg = string.Format("{0} days,", timeTillExpiry.Days);
            }

            string hourMsg = string.Empty;
            if (timeTillExpiry.Hours == 1)
            {
                hourMsg = string.Format("{0} hour,", timeTillExpiry.Hours);
            }
            else if (timeTillExpiry.Hours > 1)
            {
                hourMsg = string.Format("{0} hours,", timeTillExpiry.Hours);
            }

            string minuteMsg = string.Empty;
            if (timeTillExpiry.Minutes == 1)
            {
                minuteMsg = string.Format("{0} minute,", timeTillExpiry.Minutes);
            }
            else if (timeTillExpiry.Minutes > 1)
            {
                minuteMsg = string.Format("{0} minutes,", timeTillExpiry.Minutes);
            }

            string secondMsg = string.Empty;
            if (timeTillExpiry.Seconds == 1)
            {
                secondMsg = string.Format("{0} second", timeTillExpiry.Seconds);
            }
            else if (timeTillExpiry.Seconds > 1)
            {
                secondMsg = string.Format("{0} seconds", timeTillExpiry.Seconds);
            }
            string expiresInString = string.Format("{0} {1} {2} {3}", dayMsg, hourMsg, minuteMsg, secondMsg);
            expiresInString = "Expires in " + expiresInString.TrimStart();
            return expiresInString;
        }

    }
}
